<?php
class Solution {
    public function majorityElement($nums) {
        $map = array();
        $n = count($nums)/2;
        foreach ($nums as $num) {
            if (! isset($map[$num])) {
                $map[$num] = 0;
            }
            $map[$num] += 1;
            if ($map[$num] > $n) {
                return $num;
            }
        }
        return 0;
    }
}